-
-
Notifications
You must be signed in to change notification settings - Fork 166
feat(types): setup postgrest-13 types inference #618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat(types): setup postgrest-13 types inference #618
Conversation
src/select-query-parser/result.ts
Outdated
? ClientOptions['postgrestVersion'] extends 13 // Spread over an many-to-many relationship, turn all the result fields into arrays | ||
? ProcessManyToManySpreadNodeResult<Result> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note
Here is what the conditionality for the inference can look like.
rest13: | ||
image: postgrest/postgrest:v13.0.0 | ||
ports: | ||
- '3001:3000' | ||
environment: | ||
PGRST_DB_URI: postgres://postgres:postgres@db:5432/postgres | ||
PGRST_DB_SCHEMAS: public,personal | ||
PGRST_DB_EXTRA_SEARCH_PATH: extensions | ||
PGRST_DB_ANON_ROLE: postgres | ||
PGRST_DB_PLAN_ENABLED: 1 | ||
PGRST_DB_TX_END: commit-allow-override | ||
PGRST_DB_AGGREGATES_ENABLED: true | ||
depends_on: | ||
- db | ||
rest12: | ||
image: postgrest/postgrest:v12.2.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note
It is also possible to check if all the current tests and the new version ones are matching by upgrading the rest12
container to postgrest:v13
. I did so for testing, and except from the Spread on Many
feature, everything was behaving the same, with the only difference being the returned error message within some of the inline snapshots.
Co-authored-by: Steve Chavez <[email protected]>
Allows loosy matching over the version minor
Coverage complain for no reason there. Edit: Exclude |
export default abstract class PostgrestBuilder<Result, ThrowOnError extends boolean = false> | ||
implements | ||
export default abstract class PostgrestBuilder< | ||
ClientOptions extends ClientServerOptions, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't block the PR based on this but I have a hunch that adding new type parameters at the start/middle of the parameter list will break some 3rd party lib relying on the typings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum that's true, I've looked for usage on github: https://github.com/search?q=language%3ATypeScript++PostgrestBuilder%3C&type=code&p=3
Most of them seems to be forks though. Maybe we could pass this into a new major version though.
Or maybe in the changelog we can give a fix solution for compatibility:
import type { PostgrestBuilder as BasePostgrestBuilder } from '@supabase/posgrest-js';
type PostgrestBuilder<R, TE extends boolean = false> = BasePostgrestBuilder<{}, R, TE>
Didn't tested it but this should allow to use the PostgrestBuilder
type as before 🤔
I think I remember having trouble pushing this as a last argument because then, it required to always also define the ThrowOnError
param which has default set.
What kind of change does this PR introduce?
This lay out the ground basis to start introducing new postgrest-13 features to the client library.
new PostgrestClient(DB_URL, { postgrestVersion: 12 | 13 }>
allowing the types inference to pick in and choose the right result based on the available features for this major version.__internal_supabase
schema.